from rest_framework import serializers
from goods_info.models import UnitsModel


class UnitsSerializers(serializers.ModelSerializer):
    '''
    计量单位的序列化器和反序列化
    '''
    # 增加一个新属性，把基本单位和副单位一起展示
    units_name = serializers.SerializerMethodField(read_only=True)
    class Meta:
        model = UnitsModel
        fields = '__all__'
    def get_units_name(self,obj):  # 就是调用该对象的__str__函数
        return str(obj)